package com.itdev.matcherapp.android.fakeservice;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import com.google.android.maps.Point;

public class ServiceFaky {
	
	private static boolean isInitInstance = false;
	private static HashMap<String, String> accountMap = new HashMap<String, String>();
	private static HashMap<String, Point> curLocationMap = new HashMap<String, Point>();
	private static HashMap<String, List<ContentCategoeryBean>> peopleContentCategoeryMap = new HashMap<String, List<ContentCategoeryBean>>();
	
	public static void initInstance() {
		if (!isInitInstance) {
			isInitInstance = true;
			initAccount();
			initLocation();
			initPeopleConCat();
		}
	}

	private static void initAccount() {
		accountMap.put("kanatorn@gmail.com", "kanatorn@gmail.com");
		accountMap.put("rosippa@gmail.com", "rosippa@gmail.com");
		accountMap.put("banlung@gmail.com", "banlung@gmail.com");
	}

	private static void initLocation() {
		double lat1 = 13.902528 * 1E6;
		double lon1 = 100.534106 * 1E6;
		int latInt = (int) lat1;
		int lonInt = (int) lon1;
		Point point1 = new Point(latInt, lonInt);
		curLocationMap.put("rosippa@gmail.com", point1);
		double lat2 = 13.897095 * 1E6;
		double lon2 = 100.549155 * 1E6;
		Point point2 = new Point((int) lat2, (int) lon2);
		curLocationMap.put("banlung@gmail.com", point2);
	}
	
	private static void initPeopleConCat(){
		List<ContentCategoeryBean> contentList = new ArrayList<ContentCategoeryBean>();
	}

	public static Boolean login(String gmailAccount) {
		return accountMap.containsKey(gmailAccount);
	}

	public static Boolean updateCurrentLocation(String gmailAccount,
			Point curLocation) {
		if (accountMap.get(gmailAccount) == null) {
			return false;
		} else {
			curLocationMap.put(gmailAccount, curLocation);
			return true;
		}
	}

	public static List<PeopleLocationBean> getPeopleMatching(
			String gmailAccount, float radius) {
		List<PeopleLocationBean> result = new ArrayList<PeopleLocationBean>();
		Set keySet = curLocationMap.keySet();
		Iterator<String> keys = keySet.iterator();
		while (keys.hasNext()) {
			String curKey = keys.next();
			if (curKey.equals(gmailAccount))
				continue;
			Point location = curLocationMap.get(curKey);
			float distance = CalculateUtil.getDistanceBetweenLatLong(location,
					curLocationMap.get(gmailAccount));
			if (distance <= radius) {
				PeopleLocationBean people = new PeopleLocationBean();
				people.setGmailAccount(curKey);
				people.setLatitude(location.getLatitudeE6());
				people.setLongitude(location.getLongitudeE6());
				result.add(people);
			}
		}
		return result;
	}

	public static List<ContentCategoeryBean> getContentCategoeryList(){
		List<ContentCategoeryBean> result = new ArrayList<ContentCategoeryBean>();
		ContentCategoeryBean content = new ContentCategoeryBean();
		content.setContentCategoeryId(0);
		content.setContentCategoeryName("Book");
		result.add(content);
		
		ContentCategoeryBean content2 = new ContentCategoeryBean();
		content2.setContentCategoeryId(1);
		content2.setContentCategoeryName("Sport");
		result.add(content2);
		
		ContentCategoeryBean content3 = new ContentCategoeryBean();
		content3.setContentCategoeryId(2);
		content3.setContentCategoeryName("Night Life");
		result.add(content3);
		
		return result;
	}
}
